//
//  HNSH_BusinessCircleDetailViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/6.
//

#import "HNSH_BusinessCircleDetailViewController.h"

//view
#import "HNSH_BusinessCircleDetailHeaderView.h"
#import "HNSH_BusinessCircleDetailFooterView.h"

#import "HNSH_BusinessCircleDetailAlert.h"

@interface HNSH_BusinessCircleDetailViewController ()

/* headerView */
@property (nonatomic, strong) HNSH_BusinessCircleDetailHeaderView *headerView;

/* footerView */
@property (nonatomic, strong) HNSH_BusinessCircleDetailFooterView *footerView;

@end

@implementation HNSH_BusinessCircleDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self showNavTitle:@"店铺详情" showLeftItem:YES];
    
    [self configTopNav];
    
    [self configHeaderView];
    
    [self configFooterView];
}

- (void)setModel:(HNSH_BusinessCircleListModel *)model {
    _model = model;
    self.headerView.model = model;
    self.footerView.model = model;
}

- (void)configTopNav {
    self.tableView.backgroundColor = [UIColor appWhiteLabelColor];
    [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(kNavBarAndStatusBarHeight, 0, 0, 0));
    }];
    
    WeakSelf(weakSelf);
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"上传支付凭证" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor appBlackLabelColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    button.frame = CGRectMake(kScreenWidth-116, kStatusBarHeight, 116, 44);
    [self.view addSubview:button];
    [[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        HNSH_BusinessCircleDetailAlert *alert = [[HNSH_BusinessCircleDetailAlert alloc]initWithFrame:CGRectMake(0, 0, 287, 372) shopId:weakSelf.model.uid];
        [alert showView];
    }];
}

- (void)configHeaderView {
    self.tableView.tableHeaderView = self.headerView;
}

- (void)configFooterView {
    self.tableView.tableFooterView = self.footerView;
    WeakSelf(weakSelf);
    self.footerView.dhBlock = ^{
        NSURL * gaode_App = [NSURL URLWithString:@"iosamap://"];
        if ([[UIApplication sharedApplication] canOpenURL:gaode_App]) {
            NSString *gdString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=ios.blackfish.XHY&dlat=%f&dlon=%f&dname=%@&style=2&dev=0",weakSelf.model.latitude,weakSelf.model.longitude,weakSelf.model.address] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; //先出现地点位置，然后再手动点击导航
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:gdString] options:@{} completionHandler:nil];

        }
    };
}

#pragma mark lazy
- (HNSH_BusinessCircleDetailHeaderView *)headerView {
    if (!_headerView) {
        _headerView = [[HNSH_BusinessCircleDetailHeaderView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 253)];
    }
    return _headerView;
}

- (HNSH_BusinessCircleDetailFooterView *)footerView {
    if (!_footerView) {
        _footerView = [[HNSH_BusinessCircleDetailFooterView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 247)];
    }
    return _footerView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
